home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / dtkclk11.zip / SAVECLK.C < prev    next >
Text File  |  1993-05-05  |  1KB  |  69 lines

  1. /*
  2.  * Program to set the time on the DTK clock/calendar board.
  3.  * (C) Copyright 1989 Richard B. Wales.  All Rights Reserved.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "clkdefs.h"
  8.  
  9.  
  10. static char copyright[] =
  11. "SAVECLK -- Set DTK clock/calendar board, version 1.10\r\n\
  12. (C) Copyright 1989 Richard B. Wales";
  13.  
  14.  
  15. void main ()
  16. {    struct clockval *cv;
  17.     struct date date, *da;
  18.     struct time time, *ti;
  19.  
  20.     /*
  21.      * Identify the program.
  22.      */
  23.     printf ("%s\n", copyright);
  24.  
  25.     /*
  26.      * Get the system date and time.
  27.      */
  28.     gettime (&time); getdate (&date);
  29.  
  30.     /*
  31.      * Transform the date/time into the clock structure.
  32.      */
  33.     time_to_clock (&date, &time, &cv);
  34.     if (cv == NULL_CLOCK)
  35.     {    printf ("Garbled system date/time\n");
  36.         exit (1);
  37.     }
  38.  
  39.     /*
  40.      * Set the clock/calendar.
  41.      */
  42.     if (write_clock (cv) == NULL_CLOCK)
  43.     {    printf ("Error setting clock\n");
  44.         exit (1);
  45.     }
  46.  
  47.     /*
  48.      * Announce the new date and time on the clock board.
  49.      */
  50.     cv = read_clock ();
  51.     if (cv == NULL_CLOCK)
  52.     {    printf ("Error reading back clock\n");
  53.         exit (1);
  54.     }
  55.     clock_to_time (cv, &da, &ti);
  56.     if (da == NULL_DATE || ti == NULL_TIME)
  57.     {    printf ("Garbled date/time from clock\n");
  58.         exit (1);
  59.     }
  60.     printf ("Clock board set to %02d/%02d/%02d %02d:%02d:%02d\n",
  61.         da->da_mon, da->da_day, da->da_year % 100,
  62.         ti->ti_hour, ti->ti_min, ti->ti_sec);
  63.  
  64.     /*
  65.      * That's all.
  66.      */
  67.     exit (0);
  68. }
  69.